﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace TestDhgms.TplHelperTest.Controller.Task.CompressFile
{
    using Quartz;
    using Quartz.Impl;
    using Quartz.Impl.Triggers;
    using Quartz.Spi;

    [TestClass]
    public class Zip
    {
        [TestMethod]
        public void SingleTextFile()
        {
            System.String workingDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            String sourceFullFileName = workingDirectory + "\\SimpleTextFile.txt";
            String targetFileName = workingDirectory + "\\SimpleTextFile.zip";

            Dhgms.TplHelper.Controller.Task.CompressFile.Zip task = new Dhgms.TplHelper.Controller.Task.CompressFile.Zip(
                sourceFullFileName,
                targetFileName);

            var schedFact = new StdSchedulerFactory();
            var scheduler = schedFact.GetScheduler();
            scheduler.Start();
            
            // construct job info
            TriggerFiredBundle triggerFiredBundle = new TriggerFiredBundle(null, null, null, false, null, null, null, null);
            JobExecutionContextImpl jec = new JobExecutionContextImpl(
                scheduler,
                triggerFiredBundle,
                task);
            IJobDetail jobDetail = new Quartz.Impl.JobDetailImpl("testJob", null, typeof(Dhgms.TplHelper.Controller.Task.CompressFile.Zip));

            // fire every hour
            ITrigger trigger = new SimpleTriggerImpl("Test");
            
            // start on the next even hour
            //scheduler.ScheduleJob(jobDetail, trigger);

            task.Execute(jec);
            var taskResult = (Dhgms.TplHelper.Model.Info.TaskResult.RecordProcessor)jec.Result;
            Assert.AreEqual(System.DateTime.Today, taskResult.Started.Date);
            Assert.AreEqual(System.DateTime.Today, taskResult.Finished.Date);
            Assert.IsTrue(taskResult.Started < taskResult.Finished);
            Assert.AreEqual(1, taskResult.RecordsProcessed);
        }
    }
}
